package com.google.gwt.gfx.client.style;

import com.google.gwt.dom.client.Style.Display;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.IsWidget;

public class DefaultStyle extends GFXStyle {

	public DefaultStyle(IsWidget buddy) {
		super(buddy);
	}

	public DefaultStyle(IsWidget buddy, Element element) {
		super(buddy, element);
	}

	public int getHeight() {
		return element().getOffsetHeight();
	}

	public int getLeft() {
		return element().getOffsetLeft();
	}

	public String getProperty(String name) {
		return element().getStyle().getProperty(name);
	}

	public int getTop() {
		return element().getOffsetTop();
	}

	public int getWidth() {
		return element().getOffsetWidth();
	}

	public boolean isSelectable() {
		return !element().getPropertyString("unselectable").equals("on");
	}

	public boolean isVisible() {
		return element().getStyle().getDisplay().toLowerCase()
				.equals(Display.BLOCK.name().toLowerCase());
	}

	public void setHeight(int height) {
		buddy().asWidget().setHeight(height + "px");
	}

	public void setLeft(int left) {
		element().getStyle().setLeft(left, Unit.PX);
	}

	public void setProperty(String name, String value) {
		element().getStyle().setProperty(name, value);
	}

	public void setSelectable(boolean selectable) {
		if (selectable) {
			element().removeClassName("x-unselectable");
			element().setPropertyString("unselectable", "");
		} else {
			element().addClassName("x-unselectable");
			element().setPropertyString("unselectable", "on");
		}
	}

	public void setTop(int top) {
		element().getStyle().setTop(top, Unit.PX);
	}

	public void setVisible(boolean visible) {
		element().getStyle().setDisplay(visible ? Display.BLOCK : Display.NONE);
	}

	public void setWidth(int width) {
		buddy().asWidget().setWidth(width + "px");
	}

}
